import moment from 'moment'
export function Now(arg) {
  if (arg != null) {
    throw new Error('函数不支持参数')
  }
  return moment()
}
export function ParseTime(time) {
  if (time == null || time === '') {
    throw new Error('参数不能为空')
  } else if (time instanceof moment) {
    return time
  }
  const t = moment(time)
  if (t.isValid()) {
    return t
  }
  throw new Error('时间格式错误!')
}
export function AddDay(time, day) {
  const t = ParseTime(time)
  return t.add(day, 'd')
}

export function Date(time) {
  const t = ParseTime(time)
  return moment(t.year(), t.month(), t.day())
}

export function Format(time, str) {
  const t = ParseTime(time)
  return t.format(str)
}

export function Hour(time) {
  const t = ParseTime(time)
  return t.hour()
}

export function Second(time) {
  const t = ParseTime(time)
  return t.second()
}

export function Minute(time) {
  const t = ParseTime(time)
  return t.minute()
}

export function Year(time) {
  const t = ParseTime(time)
  return t.year()
}

export function Month(time) {
  const t = ParseTime(time)
  return t.month()
}

export function Day(time) {
  const t = ParseTime(time)
  return t.day()
}
const weekday = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
const zhWeekDay = ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
export function DayOfWeek(time, lang) {
  if (lang == null) {
    lang = 'zh'
  }
  const t = ParseTime(time)
  const day = t.weekday()
  if (lang === 'zh') {
    return zhWeekDay[day]
  }
  return weekday[day]
}

export function DayOfYear(time) {
  const t = ParseTime(time)
  return t.dayOfYear()
}

export function DateDif(one, two, format) {
  const t1 = ParseTime(one)
  const t2 = ParseTime(two)
  return t2.diff(t1, format)
}

export function Len(str) {
  if (str == null) {
    return 0
  }
  return str.length
}

export function Trim(str) {
  if (str == null) {
    return null
  }
  if (str.startsWith(' ')) {
    str = str.substring(1)
  }
  if (str.endsWith(' ')) {
    str = str.substring(str.length - 1)
  }
  return str
}

export function IsNull(str) {
  return str == null || str === ''
}
export function Substring(str, index, len) {
  if (len == null) {
    return str.substring(index)
  }
  return str.substring(index, index + len)
}
export function Split(str, spe) {
  return str.Split(spe)
}

export function Join(str, spe) {
  return str.Join(spe)
}
export function ChinaToMoney(str) {
  if (str == null) {
    throw new Error('大写数字不能为空!')
  }
  return 1.2
}

export function MoneyToChina(str) {
  if (str == null) {
    throw new Error('小写金额不能为空!')
  }
  return '一'
}

export function GetValue(array, index) {
  if (array == null) {
    throw new Error('获取的数组不能为空!')
  }
  if (index == null) {
    throw new Error('获取的索引不能为空!')
  }
  return null
}
export function Sum(arg) {
  return 0
}

export function Max(arg) {
  return 0
}
export function RowIndex() {
  return 0
}
export function Min(arg) {
  return 0
}

export function Average(arg) {
  return 0
}

export function CheckIsTrue(arg) {
  return true
}

export function CheckIsFalse(arg) {
  return true
}
export function If(arg, t, f) {
  return t
}
export function Multiply(arg, f) {
  if (arg == null || f == null) {
    throw new Error('最少2个数组参与计算')
  }
  return 3
}

export function IsTrue(arg, f) {
  if (arg == null) {
    throw new Error('判断结果参数不能为空')
  }
  if (f == null) {
    throw new Error('条件为真的取值数组不能为空')
  }
  return []
}
export function IsEquals(arg, f) {
  if (arg == null) {
    throw new Error('参数不能为空')
  }
  return true
}
export function IsFalse(arg, f) {
  if (arg == null) {
    throw new Error('判断结果参数不能为空')
  }
  if (f == null) {
    throw new Error('条件为真的取值数组不能为空')
  }
  return []
}

export function ToString(arg, f) {
  return '1'
}
export function ArrayMultiply(arg, f) {
  if (arg == null || f == null) {
    throw new Error('最少2个数组参与计算')
  }
  return []
}
export function GetDateTime() {
  return moment()
}

export function GetTimeSpan(time) {
  if (time == null) {
    throw new Error('时间参数不能为空')
  }
  return 0
}

export function FormatTime(time, format) {
  if (time == null) {
    throw new Error('时间参数不能为空')
  }
  return 0
}

export function GetTime(time, type) {
  if (time == null) {
    throw new Error('时间参数不能为空')
  }
  if (type == null) {
    throw new Error('指定类型不能为空')
  }
  return 0
}

export function Add(time, type, num) {
  if (time == null) {
    throw new Error('时间参数不能为空')
  }
  if (type == null) {
    throw new Error('操作类型不能为空')
  }
  if (num == null) {
    throw new Error('操作数不能为空')
  }
  return moment()
}

export function GetDate() {
  return moment()
}

export function MonthStart() {
  return moment()
}

export function MonthEnd() {
  return moment()
}

export function YearStart() {
  return moment()
}

export function YearEnd() {
  return moment()
}

export function GetYear() {
  return 2025
}

export function GetMonth() {
  return 8
}

export function GetDay() {
  return 20
}

export function GetHour() {
  return 11
}

export function GetMinute() {
  return 1
}
